//Search模块
import {reqGetSearchInfo} from "@/api";

const state = {
    searchInfo: {}
}

const actions = {
    async getSearchInfo({commit}, data = {}) {
        let result = await reqGetSearchInfo(data)
        if (result.code === 200) {
            commit('GETSEARCHINFO', result.data) //data至少为{}，不能时undefined
        }
    },
}

const mutations = {
    GETSEARCHINFO(state, searchInfo) {
        state.searchInfo = searchInfo
    },
}

const getters = {
    goodsList(state) {
        return state.searchInfo.goodsList || [] //防止没有获取到searchInfo时为undefined
    },
    trademarkList(state) {
        return state.searchInfo.trademarkList || []
    },
    attrsList(state) {
        return state.searchInfo.attrsList || []
    }
}//为了简化仓库中的数据

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}

